// 所有用户管理
import { ADDUSER, UPDATEUSER, DELUSER, SETUSER, SETLOADING } from '../action/usersAction'
const initialState = {
    isLoading: false,
    users: []
}
export default (state = initialState, { type, payload }) => {
    const { users, isLoading } = state
    switch (type) {
        case ADDUSER:
            return { ...state, users: [...users, payload] }
        case UPDATEUSER:
            const { id, user } = payload
            return { ...state, users: users.map(it => it.id === id ? { ...it, ...user } : it) }
        case DELUSER:
            return { ...state, users: state.filter(it => it.id !== payload) }
        case SETUSER:
            return { ...state, users: payload }
        case SETLOADING:
            return { ...state, isLoading: payload }
        default:
            return state
    }
}
